﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Workflow.Runtime;

namespace CommonWFLibrary
{
    /// <summary>
    /// When a long running job was to do it async, some context must be maintained so whenever
    /// whatever event it is waiting for fires it can call back into our system and notify us that
    /// it has finished (and pass in the various results!). 
    /// </summary>
	public class LongRunningContext
	{
        private LongRunningActivityBaseService _service;
        private LongRunningActivityInfo _info;

        internal LongRunningContext(LongRunningActivityBaseService serv, LongRunningActivityInfo info, WorkflowRuntime runtime)
        {
            _service = serv;
            _info = info;
            Runtime = runtime;
        }

        /// <summary>
        /// Gets the Workflow Runtime that this long running activity is running under
        /// </summary>
        public WorkflowRuntime Runtime { get; private set; }

        /// <summary>
        /// Finished with the long running action, this will notify the system
        /// to finish processing the activity.
        /// </summary>
        public void Complete()
        {
            Complete<object>(null);
        }

        /// <summary>
        /// Finished with the long running actino, this will notify the system to
        /// finish processing the activity. It will also pass back the result so
        /// that it can be re-inserted into the Activities various variables.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="result"></param>
        public void Complete<T>(T result)
        {
            _service.Complete(_info, result);
        }
	}
}
